#include "TcpServer3.hpp"
#include "Command.hpp"

void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " port" << std::endl;
}

// ./tcpserver port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = std::stoi(argv[1]);

    Enable_Console_Log_Strategy();

    // 1、命令的执行模块
    Command cmd;

    // 2、网络服务器模块
    // 写法1：
    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,[&cmd](const std::string& word, InetAddr &addr){
    //     return cmd.Execute(word,addr);
    // });

    // 写法2：
    // func_t f=std::bind(&Command::Execute,&cmd,std::placeholders::_1,std::placeholders::_2); // bind也是形成一个函数对象
    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,f);

    // 写法3：
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, std::bind(&Command::Execute, &cmd, std::placeholders::_1, std::placeholders::_2));
    tsvr->Init();
    tsvr->Run();

    return 0;
}
